/// <reference path="../typings/store.d.ts" />
import {MutationTree} from 'vuex'

const mutations: MutationTree<any> = {
    SET_currentComponent(state, componentName): void {
        state.currentComponent = componentName
    },
    SET_CopyMoveNodeProp(state, CopyMoveNodeProp): void {
        state.CopyMoveNodeProp = CopyMoveNodeProp
    },
    SET_nodeMoveing(state, nodeMoveing): void {
        state.nodeMoveing = nodeMoveing
    },
    SET_workspaceArea(state, data): void {
        state.workspaceArea = data
    },
    SET_projectPageList_byPageId(state, info: StoreState.projectPageList): void {
        if (state.projectPageList) {
            state.projectPageList.forEach((item: StoreState.projectPageList) => {
                // 当页面ID相等时会将传入的数据覆盖已有的组件列表数
                if (item.pageId === info.pageId) {
                    item.componentsList = info.componentsList
                    return
                }
            })
        } else {
            state.projectPageList = [info]
        }
    },
    ADD_component_byPageId(state, addComponetInfo: StoreState.addComponetInfo) {
        state.projectPageList.forEach((item: StoreState.projectPageList) => {
            if (item.pageId === addComponetInfo.pageId) {
                item.componentsList.push(addComponetInfo.componetInfo)
                return
            }
        })
    }
}

export default mutations